package com.csun.cmny.provider.controller;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.domain.OmcNursingTourRecord;
import com.csun.cmny.provider.model.dto.comments.CommentsSaveDto;
import com.csun.cmny.provider.model.dto.nuringTour.NursingTourRecordSaveDto;
import com.csun.cmny.provider.model.dto.nuringTour.NursingTourRecordSelectDto;
import com.csun.cmny.provider.model.vo.nursingTour.NursingTourRecordVo;
import com.csun.cmny.provider.pojo.Oldman;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OldmanService;
import com.csun.cmny.provider.service.OmcNursingTourRecordService;
import com.csun.cmny.util.PublicUtil;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/nursingTour", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OmcNursingTourRecordController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @Resource
    private OmcNursingTourRecordService tourRecordService;


    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "护工新增巡视记录")
    @RequestMapping(value = "/addNursingTourRecord", method = RequestMethod.POST)
    public Wrapper addNursingTourRecord(@RequestBody @Valid NursingTourRecordSaveDto nursingTourRecordSaveDto, BindingResult br) {



        OmcNursingTourRecord omcNursingTourRecord = new OmcNursingTourRecord();
        BeanUtils.copyProperties(nursingTourRecordSaveDto,omcNursingTourRecord);

        omcNursingTourRecord.setGroupId(getLoginAuthDto().getGroupId());
        omcNursingTourRecord.setNursingUserId(getLoginAuthDto().getUserId());
        omcNursingTourRecord.setNursingName(getLoginAuthDto().getUserName());


        int result = tourRecordService.save(omcNursingTourRecord);


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "查看巡视记录")
    @RequestMapping(value = "/select", method = RequestMethod.POST)
    public Wrapper selectNursingTourRecord(@RequestBody @Valid NursingTourRecordSelectDto nursingTourRecordSelectDto, BindingResult br) {

        //nursingTourRecordSelectDto.setGroupId(getLoginAuthDto().getGroupId());


        List<NursingTourRecordVo> list=tourRecordService.selectNursingTourRecord(nursingTourRecordSelectDto);

        PageInfo<NursingTourRecordVo> pageInfo = new PageInfo<>(list);


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }
}
